﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VSDBM.Code.dto;
using VSDBM.Code.dao;

public partial class Visual_Configuration_UserConfiguration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            VSDBM.Code.dto.User usuariologado1 = (VSDBM.Code.dto.User)HttpContext.Current.Session["usuariologado"];
            UserConfig config = new UserConfig();
            config = UserConfigDAO.getConfig(usuariologado1.id);

            txtWordSize.Text = Convert.ToString(config.blast_wordsize);
            txtMinDiagonalLenth.Text = Convert.ToString(config.blast_mindiagonallength);
            txtTeshold.Text = Convert.ToString(config.blast_teshold);
            txtHitScore.Text = Convert.ToString(config.blast_hitscore);
            txtMissPenality.Text = Convert.ToString(config.blast_misspenality);
            txtGapExistPenality.Text = Convert.ToString(config.blast_gapexistpenality);
            txtGapExtendPenality.Text = Convert.ToString(config.blast_gapextendpenality);
            txtUnambiguityTeshold.Text = Convert.ToString(config.blast_unambiguityscoreteshold);

        }

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        VSDBM.Code.dto.User usuariologado = (VSDBM.Code.dto.User)HttpContext.Current.Session["usuariologado"];
        UserConfig config = new UserConfig(0, usuariologado.id, Convert.ToInt32(txtWordSize.Text), Convert.ToInt32(txtMinDiagonalLenth.Text), Convert.ToInt32(txtTeshold.Text), Convert.ToSingle(txtHitScore.Text), Convert.ToSingle(txtMissPenality.Text), Convert.ToSingle(txtGapExistPenality.Text), Convert.ToSingle(txtGapExtendPenality.Text), Convert.ToSingle(txtUnambiguityTeshold.Text));
        try
        {
            UserConfigDAO.update(config);
        }
        catch (Exception ex)
        {

            HttpContext.Current.Session["exception"] = ex.Message;
            Response.Redirect("../../../Visual/Errors/error.aspx");
        }
         HttpContext.Current.Session["done"] = "User config added.";
        Response.Redirect("../../../Visual/Done/Done.aspx");

    }
}